#include"point_light.h"
#include"visibility_tester.h"
PointLight::PointLight(P3 pos, Spectrum intensity) :pos(pos), I(intensity), Light((int)LightFlags::DeltaPosition, 1) {}
Spectrum PointLight::Power() const { return I * 4 * Pi; }
Spectrum PointLight::sampleLightPt(const P3 &x, P3 *wi, Float* rands, Float *pdf, VisibilityTester *vis)
{
	//vis->setStartPt(pos);
	//vis->setTargetPt(x);
	vis->startPt = pos;
	vis->targetPt = x;
	*pdf = 1;
	*wi = (x - pos);
	Float d2 = wi->len2();
	*wi /= sqrtf(d2);

	return I / d2;
}
Float PointLight::getLightPdf(P3 &p, P3 &dir)
{
	return 1;
}
Spectrum PointLight::sampleLightOut(Ray *ray_out, P3 *norm, Float *pdfPos, Float *pdfDir, Float *rands)
{
	*ray_out = Ray(pos, uniformSampleSphere(rands));
	*norm = ray_out->d;
	*pdfPos = 1;
	*pdfDir = Inv4Pi;
	return I;
}